#include "Arduino.h"
#include "DistanceSensor.h" //include the declaration for this class

DistanceSensor::DistanceSensor(int inputPin) { 
	pinMode(inputPin, INPUT); 
}

DistanceSensor::~DistanceSensor() {

}

int DistanceSensor::getDistance() {

  double sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  float toReturn = (13.205 / (voltage - 0.057) - 0.42);
  
  if (toReturn > 50)
	return -1;
	
  return toReturn;
}